/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package kimo.bl;

import kimo.persistence.entities.Producer;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zul.Messagebox;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Textbox;

/**
 *
 * @author a381u296
 */
public abstract class KimoUI extends SelectorComposer<Component> {

    private Producer producer;
    private KimoDAO kdao;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp); //To change body of generated methods, choose Tools | Templates.
        kdao = new KimoDAO();
        producer = kdao.findById(Executions.getCurrent().getParameter("pid"));
        
        populateListboxs();
        
        
        if (producer != null) {
            updateUI();
        }
    }

    /**
     * returns the KimoDao
     * @return KimoDAO
     */
    public KimoDAO getKdao() {
        return kdao;
    }

    /**
     * returns the current Producer
     * 
     * @return Producer
     */
    public Producer getProducer() {
        return producer;
    }

    /**
     * implement here  to get the values from the ui
     */
     abstract void getFromUI();

    /**
     * implement here to update the ui
     */
    abstract void updateUI();

     /**
     * implement this to populate the list boxes
     * that are used BEFORE you have a producer
     */
    abstract void populateListboxs();

    abstract void clearUI() ;
    
    public void onSaveProducerBtnClick() throws Exception {
        getFromUI();
        if (kdao.save((producer)).equals("ok")) {
            Messagebox.show("Τα στοιχεία του παραγωγού ενημερώθηκαν");
        }
    }

   

    /**
     *
     * @return
     * @throws Exception
     */
    public String saveProducer() throws Exception {
        getFromUI();
        return kdao.save(producer);
    }
    

}
